package com.leen.admin.service.impl;


import com.leen.admin.service.CrudService;
import org.springframework.data.repository.CrudRepository;

import java.util.Optional;

public class CurdServiceImpl<T,ID> implements CrudService<T,ID> {
    //父（多态）
    private CrudRepository crudRepository;

    /**
     * 预留给子类给赋值
     * @param crudRepository
     */
    public void setCrudRepository(CrudRepository crudRepository){
        this.crudRepository=crudRepository;
    }

    @Override
    public void deletefindById(ID var) {
        this.crudRepository.deleteById(var);
    }

    @Override
    public <S extends T> S save(S entity){
        return (S) this.crudRepository.save(entity);
    }

    @Override
    public <S extends T> Iterable<S> saveAll(Iterable<S> entities){
        return this.crudRepository.saveAll(entities);
    }

    @Override
    public Optional<T> findById(ID id){
        return this.crudRepository.findById(id);
    }

    @Override
    public boolean existsById(ID id){
        return this.crudRepository.existsById(id);
    }

    @Override
    public Iterable<T> findAll(){
        return this.crudRepository.findAll();
    }


    @Override
    public Iterable<T>findAllById(Iterable<ID>ids){
        return this.crudRepository.findAllById(ids);
    }

    @Override
    public long count() {
        return this.crudRepository.count();
    }

    @Override
    public void deleteById(ID var1) {
        this.crudRepository.deleteById(var1);
    }


}



























